package wechat

import (
	"fmt"
	"github.com/medivhzhan/weapp/v2"
)

type Service struct {
	AppID     string
	AppSecret string
}

func (s *Service) Resolve(code string) (string, error) {

	loginResp, err := weapp.Login(s.AppID, s.AppSecret, code)

	if err != nil {
		return "", fmt.Errorf("weaap.Login error: %v", err)
	}

	if loginResp.GetResponseError() != nil {
		return "", fmt.Errorf("weaap response error: %v", err)
	}

	return loginResp.OpenID, nil
}
